module maths.CoordSys;

private {
	import maths.Vec;
	import maths.Quat;
	import maths.Matrix;
}



struct CoordSys {
	vec3fi	origin;
	quat		rotation;
	
	static const CoordSys identity = { origin: vec3fi.zero, rotation: quat.identity };
	
	
	CoordSys opIn(CoordSys reference) {
		CoordSys res;
		res.origin = reference.origin;
		res.origin += reference.rotation.xform(this.origin);
		res.rotation = reference.rotation * this.rotation;
		return res;
	}


	void invert() {
		rotation.invert();
		origin = rotation.xform(-origin);
	}


	mat4 getMatrix() {
		mat4 res = rotation.getMatrix();
		res.setTranslation(vec3.init.convert(this.origin));		// .init is here to circumvent a bug in dmd .174
		return res;
	}
}
